2020-2021 Sunseeker Telemetry and Lighting System
ucs_ex3_XT1SourcesACLK.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
60 //******************************************************************************
61 
62 #include "driverlib.h"
63 
64 //*****************************************************************************
65 //
66 //Variable to store status of Oscillator fault flags
67 //
68 //*****************************************************************************
69 uint16_t status;
70 
71 void main (void)
72 {
73  //Stop watchdog timer
74  WDT_A_hold(WDT_A_BASE);
75 
76  //Set P1.0 to output direction
77  GPIO_setAsOutputPin(
78  GPIO_PORT_P1,
79  GPIO_PIN0
80  );
81 
82  //Set P11.0 to output direction
83  //P11.0 to output ACLK
84  //Select XT1
85  GPIO_setAsPeripheralModuleFunctionOutputPin(
86  GPIO_PORT_P11,
87  GPIO_PIN0
88  );
89 
90  //Port select XT1
91  GPIO_setAsPeripheralModuleFunctionInputPin(
92  GPIO_PORT_P7,
93  GPIO_PIN0 + GPIO_PIN1
94  );
95 
96  //Initializes the XT1 crystal oscillator with no timeout
97  //In case of failure, code hangs here.
98  //For time-out instead of code hang use UCS_turnOnLFXT1WithTimeout()
99  UCS_turnOnLFXT1(
100  UCS_XT1_DRIVE_0,
101  UCS_XCAP_3
102  );
103 
104 
105  // Enable global oscillator fault flag
106  SFR_clearInterrupt(SFR_OSCILLATOR_FAULT_INTERRUPT);
107  SFR_enableInterrupt(SFR_OSCILLATOR_FAULT_INTERRUPT);
108 
109  // Enable global interrupt
110  __bis_SR_register(GIE);
111 
112  //Enter LPM3 w/ interrupts
113  __bis_SR_register(LPM3_bits + GIE);
114 
115  //For debugger
116  __no_operation();
117 }
118 
119 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
120 #pragma vector=UNMI_VECTOR
121 __interrupt
122 #elif defined(__GNUC__)
123 __attribute__((interrupt(UNMI_VECTOR)))
124 #endif
125 void NMI_ISR(void)
126 {
127  do {
128  // If it still can't clear the oscillator fault flags after the timeout,
129  // trap and wait here.
130  status = UCS_clearAllOscFlagsWithTimeout(1000);
131  } while(status != 0);
132 }
__no_operation()
void NMI_ISR(void)
uint16_t status
void main(void)